/****************************************************************
 * Fulguro
 * Copyright (C) 2004 Christophe Clienti
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 ***************************************************************/


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <flgrCoreSlideWindow.h>
#include <flgrCoreNhbManage.h>
#include <flgrCoreCopy.h>
#include <flgrCoreDispatch.h>
#include <flgrCoreCompare.h>
#include <flgrCoreReplace.h>

#include <flgrArith.h>

#include <flgrMorphoLabel.h>
#include <flgrHistogram.h>
#include "skiz.h"

#define max(x,y) (x<y?y:x)

/* //////////////////////////////////////////////////////////////// */
/* // Macro for different type of dilateSeparateLabelNhb */
/* //////////////////////////////////////////////////////////////// */
/* #define dilSepLblNhb(dtype)				\ */
/*   int i,size;						\ */
/*   dtype maxi;						\ */
/*   dtype *pextr;						\ */
/*   dtype center;						\ */
/* 							\ */
/*   pextr=(dtype *) extr->listValue;			\ */
/*   center = *((dtype *) (extr->centerValue));		\ */
/*   size=extr->size;					\ */
/*   maxi=pextr[0];					\ */
/* 							\ */
/*   for(i=0 ; i<extr->size; i++) {			\ */
/*     maxi=max(maxi,pextr[i]);				\ */
/*   }							\ */
/* 							\ */
/*   if(center==maxi) return center;			\ */
/* 							\ */
/*   for(i=0 ; i<extr->size ; i++) {			\ */
/*     if((pextr[i]!=maxi) && (pextr[i]!=0)) return 0;	\ */
/* 							\ */
/*   }							\ */
/* 							\ */
/*   return maxi */

/* fgUINT8 dilateSeparateLabelNhb_fgUINT8(FLGR_Data2D *nhb, FLGR_NhbBox2D *extr) { */
/*     dilSepLblNhb(fgUINT8); */
/* } */

/* fgUINT16 dilateSeparateLabelNhb_fgUINT16(FLGR_Data2D *nhb, FLGR_NhbBox2D *extr) { */
/*     dilSepLblNhb(fgUINT16); */
/* } */

/* fgUINT32 dilateSeparateLabelNhb_fgUINT32(FLGR_Data2D *nhb, FLGR_NhbBox2D *extr) { */
/*     dilSepLblNhb(fgUINT32); */
/* } */

/* fgINT8 dilateSeparateLabelNhb_fgINT8(FLGR_Data2D *nhb, FLGR_NhbBox2D *extr) { */
/*     dilSepLblNhb(fgINT8); */
/* } */

/* fgINT16 dilateSeparateLabelNhb_fgINT16(FLGR_Data2D *nhb, FLGR_NhbBox2D *extr) { */
/*     dilSepLblNhb(fgINT16); */
/* } */

/* fgINT32 dilateSeparateLabelNhb_fgINT32(FLGR_Data2D *nhb, FLGR_NhbBox2D *extr) { */
/*     dilSepLblNhb(fgINT32); */
/* } */

/* fgFLOAT32 dilateSeparateLabelNhb_fgFLOAT32(FLGR_Data2D *nhb, FLGR_NhbBox2D *extr) { */
/*     dilSepLblNhb(fgFLOAT32); */
/* } */

/* fgFLOAT64 dilateSeparateLabelNhb_fgFLOAT64(FLGR_Data2D *nhb, FLGR_NhbBox2D *extr) { */
/*     dilSepLblNhb(fgFLOAT64); */
/* } */






/* void ImGeoSkizByLabelDilate_fgUINT8(FLGR_Data2D *imgdest, FLGR_Data2D *imgsrc, FLGR_Data2D *imgmarker, FLGR_Data2D *nhb) { */
/*   FLGR_Data2D *imglabel,*imgtmp1,*imgtmp2,*imgtmp3; */
/*   int nblabel; */
/*   fgUINT8 _254=254; */
/*   fgUINT8 _255=255; */
/*   fgUINT8 _0=0; */
/*   int raiselevel; */

/*   imglabel = flgr2d_create_pixmap(imgdest->size_y, imgdest->size_x, imgdest->type); */
/*   imgtmp1=flgr2d_create_pixmap(imgdest->size_y, imgdest->size_x, imgdest->type); */
/*   imgtmp2=flgr2d_create_pixmap(imgdest->size_y, imgdest->size_x, imgdest->type); */
/*   imgtmp3=flgr2d_create_pixmap(imgdest->size_y, imgdest->size_x, imgdest->type); */

/*   nblabel=flgr2d_label(imglabel,imgmarker,nhb->connexity); */
  
/*   flgr2d_arith_const_addsat_fgUINT8(imgsrc,imgsrc,1);  */
/*   flgr2d_replace_I_with_C_C_I(imgsrc,imgsrc,"==",&_255,&_254,imgsrc); */
/*   flgr2d_replace_I_with_C_C_I(imgsrc,imgmarker,"==",&_255,&_0,imgsrc); */


/*   for(raiselevel=0 ; raiselevel<255; raiselevel++) { */

/*     flgr2d_replace_I_with_C_C_C(imgtmp1,imgsrc,"<=",&raiselevel,&_255,&_0); */
   

/*     while(1) { */
/*       flgr2d_copy(imgtmp2,imglabel); */
      
/*       flgr2d_raster_slide_window_fgUINT8(imglabel,imgtmp2,nhb,FLGR_NHB_NO_SYM,dilateSeparateLabelNhb_fgUINT8); */
/*       flgr2d_arith_inf_fgUINT8(imglabel,imglabel,imgtmp1); */

/*       if(flgr2d_compare(imglabel,"==",imgtmp2)==0) break; */
/*     } */

/*   } */

/*   flgr2d_copy(imgdest,imglabel); */

/*   flgr2d_destroy(imglabel); */
/*   flgr2d_destroy(imgtmp1); */
/*   flgr2d_destroy(imgtmp2); */
/*   flgr2d_destroy(imgtmp3); */
/* } */

/* void ImGeoSkizBiasByLabelDilate_fgUINT8(FLGR_Data2D *imgdest, */
/* 				      FLGR_Data2D *imgsrc, */
/* 				      FLGR_Data2D *imgmarker, */
/* 				      FLGR_Data2D *nhb, */
/* 				      int graymax, int stepbylevel) { */

/*   FLGR_Data2D *imglabel,*imgtmp1,*imgtmp2,*imgtmp3; */
/*   int nblabel; */
/*   fgUINT8 _255=255; */
/*   fgUINT8 _0=0; */
/*   fgUINT8 graymax_m1= graymax - 1; */
/*   int raiselevel,j,k=0; */
/*   char name[30]; */

/*   imglabel=flgr2d_create_pixmap(imgdest->size_y, imgdest->size_x, imgdest->type); */
/*   imgtmp1=flgr2d_create_pixmap(imgdest->size_y, imgdest->size_x, imgdest->type); */
/*   imgtmp2=flgr2d_create_pixmap(imgdest->size_y, imgdest->size_x, imgdest->type); */
/*   imgtmp3=flgr2d_create_pixmap(imgdest->size_y, imgdest->size_x, imgdest->type); */

/*   nblabel=flgr2d_label(imglabel,imgmarker,nhb->connexity); */
/*   flgr_normalize_str(imglabel,imglabel,"80","255"); */

/*   flgr2d_arith_const_addsat_fgUINT8(imgsrc,imgsrc,1);  */
/*   flgr2d_replace_I_with_C_C_I(imgsrc,imgsrc,"==",&graymax,&graymax_m1,imgsrc); */
/*   flgr2d_replace_I_with_C_C_I(imgsrc,imgmarker,"==",&_255,&_0,imgsrc); */

/*   raiselevel=0; */
/*   //for(raiselevel=0 ; raiselevel<graymax; raiselevel++) { */
/*   while(1) { */
/*     raiselevel++; */
/*     if(raiselevel==graymax) raiselevel=graymax-1; */

/*     flgr2d_replace_I_with_C_C_C(imgtmp1,imgsrc,"<=",&raiselevel,&_255,&_0); */
   
/*     for(j=0;j<stepbylevel;j++) { */
/*       flgr2d_copy(imgtmp2,imglabel); */
      
/*       flgr2d_raster_slide_window_fgUINT8(imglabel,imgtmp2,nhb,FLGR_NHB_NO_SYM,dilateSeparateLabelNhb_fgUINT8); */
/*       flgr2d_arith_inf_fgUINT8(imglabel,imglabel,imgtmp1); */
     

/*     } */
/*     if(raiselevel==graymax-1) */
/*       if(flgr2d_compare(imglabel,"==",imgtmp2)==0) break; */

/*     sprintf(name,"label_%04d",k++); */
/*     //flgr_image_save_pgm(imglabel,name); */

/*   } */


/*   while(1) { */
/*     flgr2d_copy(imgtmp2,imglabel); */
      
/*     flgr2d_raster_slide_window_fgUINT8(imglabel,imgtmp2,nhb,FLGR_NHB_NO_SYM,dilateSeparateLabelNhb_fgUINT8); */
/*     //flgr2d_arith_inf_fgUINT8(imglabel,imglabel,imgtmp1); */

/*     sprintf(name,"label_%04d",k++); */
/*     //saveImage2DToPgm(imglabel,name); */

/*     if(flgr2d_compare(imglabel,"==",imgtmp2)==0) break; */
/*   } */

/*   flgr2d_copy(imgdest,imglabel); */

/*   flgr2d_destroy(imglabel); */
/*   flgr2d_destroy(imgtmp1); */
/*   flgr2d_destroy(imgtmp2); */
/*   flgr2d_destroy(imgtmp3); */
/* } */
